package com.westar.tv.utils;

import android.os.Environment;
import com.westar.tv.Config;
import java.io.File;

/**
 * Created by Administrator on 2016/6/30.
 */
public class FilesUtils {

    /**
     * 获取文件存储目录
     * @return
     */
    public static String getFileStorageDirectory(){
        File file = new File(Environment.getExternalStorageDirectory(), Config.FILE_RECV);
        if (!file.exists()) {
            file.mkdirs();
        }
        return file.getAbsolutePath()+"/";
    }

    //计算文件大小
    public static String getFileSize(long fileLength){
        if (fileLength<1)
            throw new IllegalArgumentException();
        //计算文件大小
        String sizem = MathExtend.divide(fileLength, 1024, 2);
        String dw = "KB";
        if (Float.parseFloat(sizem) > 1024) {
            sizem = MathExtend.divide(sizem, String.valueOf(1024), 2);
            dw = "M";
            if (Float.parseFloat(sizem) > 1024) {
                sizem = MathExtend.divide(sizem, String.valueOf(1024), 2);
                dw = "G";
            }
        }
        return MathExtend.delZero(sizem)+dw;
    }

}
